 #include"Image.h"
#include "Game/dConfig.h"
#include "Game/Game.h"
namespace LTGame{
	Image::Image(void){
		m_texture = NULL;
	}

	Image::~Image(void){
		m_texture->release();
	}

	Image::Image(const char* fileimage){
 		m_texture=cocos2d::CCTextureAtlas::textureAtlasWithFile(fileimage, 1);
 		m_texture->retain();
	}

	void Image::setPosition( float x,float y,float w, float h, float sx, float sy,int flix, LTCOLOR* color){	
		ccV3F_C4B_T2F_Quad t=Tools::setModule(x-w/2,y-h/2,w,h,sx,sy,m_texture->getTexture(),flix,color);
		m_texture->updateQuad( &t,0);
	}

	void Image::drawPicture(){
		m_texture->drawQuads();
	}

	float Image::getImgW(){
		return m_texture->getTexture()->getContentSize().width;
	}

	float Image::getImgH(){
	  return	m_texture->getTexture()->getContentSize().height;
	}	
	void Image::setPosition_special(float x,float y,float w, float h, float sx, float sy,int flix,LTCOLOR* color,int Anthor)
	{
		switch(Anthor){
		case ANCHOR_LV:
			y -= h/2;
			break;
		case ANCHOR_LB:
			y -=  h;
			break;
		case ANCHOR_HB:
			y -= h;
			x -= w/2;
			break;
		case ANCHOR_HB_LINE:
			x -= w/2;
			y -= h/3;
			break;
		case ANCHOR_HT:
			x -= w/2;
			break;
		case ANCHOR_HV:
			x -= w/2;
			y -= h/2;
			break;
		case ANCHOR_RB:
			x -= w;
			y -= h;
			break;
		case ANCHOR_RT:
			x -= w;
			break;
		case ANCHOR_RV:
			x -= w;
			y -= h/2;
			break;
		default:
			break;
		}
		ccV3F_C4B_T2F_Quad t=Tools::setModule(/*x-w/2,y-h/2*/x,y,w,h,sx,sy,m_texture->getTexture(),flix,color);
		m_texture->updateQuad(&t,0);
	}

	void Image::drawImageNum(Image *img,int num,float x,float y,byte Anchor)
	{
		int numW = (int)(img->getImgW()/10);
		int i = Tools::getNumDigit(num);
		int k;
		for (int j = 0;j<i;j++)
		{
			k = num % 10;
			num = num/10;
			img->setPosition_special(x+i*numW-(j+1)*numW,y,(float)numW,img->getImgH(),(float)k*numW,0,0,NULL,Anchor);
			img->drawPicture();
		}
	}
	void Image::drawHpMp(Image*img,float x,float y,float w, float h, float sx, float sy)
	{
		img->setPosition_special(x,y,w,h,0, 0, 0, NULL,ANCHOR_LT);
		img->drawPicture();
	}


}